home *** CD-ROM | disk | FTP | other *** search
- Path: iona.ie!this
- From: akohli@iona.com (Aman S Kohli)
- Newsgroups: comp.lang.c++
- Subject: Re: How to print a enum variable's names
- Date: 9 Jan 1996 10:02:47 GMT
- Organization: Iona Technologies
- Message-ID: <4cteg7$16r@pointer.dublin.iona.ie>
- NNTP-Posting-Host: this.dublin.iona.ie
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- Hi,
-
- Why not just overload the << operator? Here's a stupid example: ( All
- copyrights are willfully acknowledged ):
-
- #include <iostream.h>
-
- enum Flinstones { Fred, Willma, Pebbles };
- ostream& operator<<( ostream& _strm, Flinstones f ) {
- static char * enumValue[] = { "Fred", "Willma", "Pebbles" };
- _strm << enumValue[ f ];
- return _strm;
- }
-
- main() {
- Flinstones MyFavorite = Pebbles;
- cout << MyFavorite << " is my favorite Flinstone.\n";
- }
-
-
- Enjoy
-